<!--
 * @Date: 2022-03-25 19:00:36
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-03-26 14:44:18
 * @FilePath: \vue3Components\src\components\listShow\index.vue
 * @Description: something 
-->
<template>
  <el-tabs>
    <el-tab-pane v-for="(item, index) in listData" :key="index" :label="item.title">
      <el-scrollbar max-height="400px">
        <!-- 消息内容 -->
        <div
          class="container"
          v-for="(content, i) in item.content"
          :key="i"
          @click="clickItem(content, i)"
        >
          <div class="avatar" v-if="content.avatar">
            <el-avatar size="small" :src="content.avatar"></el-avatar>
          </div>
          <div class="content">
            <div class="title">
              {{ content.title }}
              <el-tag v-if="content.tag" size="small" :type="content.tagType">{{ content.tag }}</el-tag>
            </div>
            <div class="time" v-if="content.desc">{{ content.desc }}</div>
            <div class="time" v-if="content.time">{{ content.time }}</div>
          </div>
        </div>
        <div class="actions">
          <div
            class="a-item"
            :class="{ 'border': i !== actions.length }"
            v-for="(action, i) in actions"
            :key="i"
            @click="clickAction(action, i)"
          >
            <div class="a-icon" v-if="action.icon">
              <component :is="`el-icon-${toLine(action.icon)}`" style="width: 1em; height: 1em;"></component>
            </div>
            <div class="a-text">{{ action.text }}</div>
          </div>
        </div>
      </el-scrollbar>
    </el-tab-pane>
  </el-tabs>
</template>
 <script lang='ts' setup>
import { PropType, ref } from 'vue'
import { toLine } from '../../utils'
import { ListOptions, ActionOptions, ListItem } from './type'
const props = defineProps({
  listData: {
    //这类型真是我哥来的
    type: Array as PropType<any[]>,
    required: true
  },
  // 操作的内容
  actions: {
    type: Array as PropType<ActionOptions[]>,
    default: () => []
  }
})
const emits = defineEmits(['clickItem', 'clickAction'])
const clickAction = (item: ActionOptions, index: number) => {
  emits('clickAction', { item, index })
}
const clickItem = (item: ListItem, index: number) => {
  emits('clickItem', { item, index })
}
let activeName = ref('first')
</script>
<style lang='less' scoped>
:deep(.el-tabs__nav) {
  width: 100%;
  display: flex;
  .el-tabs__item {
    flex: 1;
    text-align: center;
  }
}
.container {
  display: flex;
  align-items: center;
  padding: 12px 10px;
  cursor: pointer;
  &:hover {
    background-color: #e6f6ff;
  }

  .content {
    flex: 3;
    padding: 0.625rem;
    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
    }
    .time {
      font-size: 12px;
      color: #999;
      margin-top: 4px;
    }
  }
}
.actions {
  height: 50px;
  display: flex;
  align-items: center;
  border-top: 1px solid #eee;
  .a-item {
    height: 50px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    .a-icon {
      margin-right: 4px;
      position: relative;
      top: 2px;
    }
    .a-text {
      font-size: 12px;
    }
  }
}
.border {
  border-right: 1px solid #eee;
}
</style>